// components/tabbar/tabbar.js
const myBehavior = require("../../behaviors/requests")
Component({
  /**
   * 组件的属性列表
   */
  behaviors: [myBehavior],
  properties: {
    active: {
      type: String,
      value: ''
    },
    home_src: {
      type: String,
      value: 'https://logisticsengineering.gree.com/img/home_h_2.png'
    },
    my_src: {
      type: String,
      value: 'https://logisticsengineering.gree.com/img/my_h_2.png'
    },
  },

  /**
   * 组件的初始数据
   */
  data: {
    base_urlstr: "https://logisticsengineering.gree.com",
    dot_flag: false
  },
  attached() {
    this.getDatas()

  },
  /**
   * 组件的方法列表
   */
  methods: {
    // 获取待办任务数据
    getDatas() {

      let url = this.data.base_urlstr + "/pfep2_api/personal_task_manage/query_current_total_task";
      let data = {
        page: 1,
        page_size: 1,
        query_cond: {

        },
        database: ""
      }
      this.post(url, data).then(res => {
        // console.log("获取待办任务数据", res)


        if (res.code == 20000) {
          if (res.data.total > 0) {
            this.setData({
              dot_flag: true,
            })
          }


        } else {
          this.setData({
            task_count: 0,
          })

        }
      }).catch(err => {
        this.setData({
          task_count: 0,
        })

      })



    },
    onChange(event) {
      console.log(event.detail);
      this.setData({ active: event.detail });
      let val = event.detail
      if (val == "home") {
        wx.redirectTo({
          url: '/pages/home1/home1',
        })
        this.setData({
          home_src: "https://logisticsengineering.gree.com/img/home_l_2.png",
          my_src: "https://logisticsengineering.gree.com/img/my_h_2.png",
        })
      } else if (val == "search") {
        wx.redirectTo({
          url: '/packageB/pages/package/task_manager/task_manager',
        })
        this.setData({
          home_src:"https://logisticsengineering.gree.com/img/home_h_2.png",
          my_src:"https://logisticsengineering.gree.com/img/my_h_2.png",
        })
      } else {
        wx.redirectTo({
          url: '/pages/user_info/user_info',
        })
        this.setData({
          home_src: "https://logisticsengineering.gree.com/img/home_h_2.png",
          my_src: "https://logisticsengineering.gree.com/img/my_l_2.png",
        })
      }
    },

  }
})
